import { _decorator, Component, Node, tween, Vec3 } from 'cc';
import { BaseComponent } from '../../Manager/UIManager/BaseComponent';
import { BunManger } from '../../Tool/BunManger';
import { GlobalData } from '../../Data/GlobalData';
import { PlateLoad } from './PlateLoad/PlateLoad';
import { StickLoad } from './StickLoad/StickLoad';
const { ccclass, property } = _decorator;

@ccclass('GameScene')
export class GameScene extends BaseComponent {

    //盘子层
    @property(Node)
    private PlateLoad: Node = null;

    //筷子层
    @property(Node)
    private StickLoad: Node = null;

    //盘子
    @property(Node)
    private Plate0: Node = null;
    @property(Node)
    private Plate1: Node = null;
    @property(Node)
    private Plate2: Node = null;

    protected Init(): void {

    }

    protected OnShow(): void {
        GlobalData.CurrentLevel = 0;
        this.UpdateLevel();
    }

    /**
     * 更新关卡
     */
    public UpdateLevel() {

        this.Plate0.active = true;
        this.Plate1.active = true;
        this.Plate2.active = false;

        this.Plate0.setPosition(new Vec3(0, 360, 0));
        this.Plate1.setPosition(new Vec3(0, 330, 0));
        this.Plate2.setPosition(new Vec3(0, 300, 0));

        if (GlobalData.CurrentLevel == 0) {
            this._UpdateLevel();
        } else {

            this.Plate2.active = true;

            tween(this.Plate0).to(0.3, { position: new Vec3(-1000, 360, 0) }).start();
            tween(this.Plate1).to(0.3, { position: new Vec3(0, 360, 0) }).start();
            tween(this.Plate2).to(0.3, { position: new Vec3(0, 330, 0) }).call(() => {
                this._UpdateLevel();
            }).start();
        }

    }

    /**
     * 更新关卡
     */
    public _UpdateLevel() {
        for (let i = 0; i < 15; i++) {
            BunManger.instance.CreateBunNum();
        }

        this.PlateLoad.getComponent(PlateLoad).UpdateLevel();
        this.StickLoad.getComponent(StickLoad).UpdateLevel();

        GlobalData.CurrentLevel++;
    }

    /**
     * 点击设置按钮
     */
    private SetClick() {
        app.logManager.debug("点击设置按钮")
        GlobalData.CurrentLevel = 0;
        this.UpdateLevel();
    }

    /**
     * 点击排行榜按钮
     */
    private RankClick() {
        app.logManager.debug("点击排行榜按钮")
    }
}


